package com.sinoglobal.ningxia.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListAdapter;
import android.widget.TextView;

import com.sinoglobal.ningxia.R;
import com.sinoglobal.ningxia.beans.EnentsDataVo;
import com.sinoglobal.ningxia.http.ConnectionUtil;

import net.tsz.afinal.FinalBitmap;

import java.util.ArrayList;

/**
 * 
 * @author zbl
 * @createdate 2014-6-26 下午2:31:35
 * @Description:首界面中"活动"的信息的adapter
 */

public class EnentsAdapter extends BaseAdapter implements ListAdapter {

	private Context context;
	private ArrayList<EnentsDataVo> enentsData = new ArrayList<EnentsDataVo>();
	private FinalBitmap fb;

	public EnentsAdapter(Context context) {
		this.context = context;
		fb = FinalBitmap.create(context);
	}

	public ArrayList<EnentsDataVo> getEnents_data() {
		return enentsData;
	}

	public void setEnents_data(ArrayList<EnentsDataVo> enentsData) {
		this.enentsData = enentsData;
	}

	public void setResult(ArrayList<EnentsDataVo> result2) {
		if (enentsData == null) {
			enentsData = new ArrayList<EnentsDataVo>();
		}
		enentsData.addAll(result2);
	}

	@Override
	public int getCount() {
		if (enentsData == null) {
			return 0;
		}
		return enentsData.size();
	}

	@Override
	public Object getItem(int position) {
		return enentsData.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if (convertView == null) {
			holder = new ViewHolder();
			convertView = LayoutInflater.from(context).inflate(R.layout.activities_conent_item, null);
			holder.enentsImgUrl = (ImageView) convertView.findViewById(R.id.activities_items_img);
			holder.enentsTitle = (TextView) convertView.findViewById(R.id.activities_items_text);
			convertView.setTag(holder);
		}
		holder = (ViewHolder) convertView.getTag();
		fb = FinalBitmap.create(context);
		fb.configLoadfailImage(R.drawable.default43);
		fb.configLoadingImage(R.drawable.default43);
		String URL=ConnectionUtil.localUrl+enentsData.get(position).getEnent_img();
		fb.display(holder.enentsImgUrl, URL);
		holder.enentsTitle.setText(enentsData.get(position).getEnent_name());

		return convertView;
	}

	class ViewHolder {
		ImageView enentsImgUrl;// 图片的显示
		TextView enentsTitle;// 活动名称

	}

}
